####################################################################
## author:    Robert A. Huber
## contact:   robert.huber@ir.gess.ethz.ch
## file name: pc_uk_recode.R
## Context:   Populism and Climate Sceptism, individuals from BES
## started:   2016-10-12
## Summary:   Loads and Recodes data
######################################################################


# British Citizens --------------------------------------------------------

# Load Data ---------------------------------------------------------------

#df_bes <- read.dta("./original data/BES2015_W7_v1.3.dta", convert.factors = F)
df_bes <- read.dta13("./original data/BES2015_W7_v1.3.dta", convert.factors = T)

df_bes <- subset(df_bes, is.na(df_bes$populism1) == F)

# Data Manipulation -------------------------------------------------------


# Dependent Variables -----------------------------------------------------

df_bes$enviroGrowth <- ifelse(df_bes$enviroGrowth == "Don't know", NA,
                              abs(as.numeric(df_bes$enviroGrowth) - 11))

df_bes$enviroProtection_RBC <- ifelse(df_bes$enviroProtection == "Not gone nearly far enough" | df_bes$enviroProtection == "Not gone far enough", "Not enough",
                                      ifelse(df_bes$enviroProtection == "About right", "About right",
                                             ifelse(df_bes$enviroProtection == "Gone too far" | df_bes$enviroProtection == "Gone much too far", "Gone too far", "Don't know")))

#df_bes$climateChange <- ifelse(df_bes$climateChange == "1", "Climate changing due to human activity",
                               # ifelse(df_bes$climateChange == "2", "Climate changing but not due to human activity",
                               #        ifelse(df_bes$climateChange == "3", "Climate not changing",
                               #               ifelse(df_bes$climateChange == "9999", "Don't know", NA))))

# Independent Variables ---------------------------------------------------

df_bes$populism1 <- factor(as.numeric(df_bes$populism1), 
                           labels =  c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$populism2 <- factor(as.numeric(df_bes$populism2), 
                           labels = c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$populism4 <- factor(as.numeric(df_bes$populism4), 
                           labels = c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$populism5 <- factor(as.numeric(df_bes$populism5), 
                           labels = c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$populism6 <- factor(as.numeric(df_bes$populism6), 
                           labels = c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$lr <- ifelse(df_bes$leftRight == "Don't know", NA,
                    ifelse(df_bes$leftRight == "Left", 1,
                           ifelse(df_bes$leftRight == "Right", 10, 
                                  as.numeric(df_bes$leftRight))))

df_bes$satDem <- ifelse(df_bes$satDemUK == "Don't know", NA,
                        as.numeric(df_bes$satDemUK))

df_bes$inc <- ifelse(df_bes$profile_gross_personal == "Prefer not to answer" | df_bes$profile_gross_personal == "Don't know", NA,
                     as.numeric(df_bes$profile_gross_personal))

df_bes$inc_house <- ifelse(df_bes$profile_gross_household == "Prefer not to answer" | df_bes$profile_gross_household == "Don't know", NA,
                           as.numeric(df_bes$profile_gross_household))

df_bes$edu_high <- ifelse(df_bes$education == "Don't know" | df_bes$education == "Prefer not to say", NA,
                          ifelse(df_bes$education == "University diploma" | 
                                   df_bes$education == "University or CNAA first degree (eg BA, B.Sc, B.Ed)" | 
                                   df_bes$education == "University or CNAA higher degree (eg M.Sc, Ph.D)" |
                                   df_bes$education == "Other technical, professional or higher qualification", 1, 0))

df_bes$edu_high <- factor(df_bes$edu_high, levels = c(0,1),labels = c("0" = "No university degree", "1" = "University degree"))

df_bes$polAttention <-ifelse(df_bes$polAttention == "Don't know", NA,
                             ifelse(df_bes$polAttention == "Pay no attention", 0, 
                                    ifelse(df_bes$polAttention == "Pay a great deal of attention", 10, as.numeric(df_bes$polAttention))))

df_bes$partyId_ukip <- ifelse(df_bes$partyId == "United Kingdom Independence Party (UKIP)", 1, 0)

df_bes$partyId_con <- ifelse(df_bes$partyId == "Conservative", 1, 0)

df_bes$partyId_lab <- ifelse(df_bes$partyId == "Labour", 1, 0)

df_bes$partyId_lib <- ifelse(df_bes$partyId == "Liberal Democrat", 1, 0)

df_bes$partyId_gre <- ifelse(df_bes$partyId == "Green Party", 1, 0)

df_bes$partyId_oth <- ifelse(df_bes$partyId != "No - none" & df_bes$partyId != "United Kingdom Independence Party (UKIP)" & df_bes$partyId != "Conservative" &df_bes$partyId != "Labour" & df_bes$partyId != "Liberal Democrat" & df_bes$partyId != "Green Party", 1, 0)

df_bes$efficacyPolCare <- factor(as.numeric(df_bes$efficacyPolCare), 
                                 labels =  c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$efficacyNoMatter <- factor(as.numeric(df_bes$efficacyNoMatter), 
                                  labels =  c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$efficacyNotUnderstand <- factor(as.numeric(df_bes$efficacyNotUnderstand), 
                                       labels =  c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$efficacyUnderstand <- factor(as.numeric(df_bes$efficacyUnderstand), 
                                    labels =  c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$efficacyTooMuchEffort <- factor(as.numeric(df_bes$efficacyTooMuchEffort), 
                                       labels =  c("1" = "Strongly disagree", "2" = "Disagree", "3" = "Neither agree nor disagree", "4" = "Agree", "5" = "Strongly agree", "6" = "Don't know"))

df_bes$riskTaking <- as.numeric(df_bes$riskTaking)

df_bes$econPersonalRetro <- ifelse(df_bes$econPersonalRetro == "Don't know", NA,
                                   as.numeric(df_bes$econPersonalRetro))

df_bes$econGenRetro <- ifelse(df_bes$econGenRetro == "Don't know", NA,
                                   as.numeric(df_bes$econGenRetro))


# df_bes$trustMPs <- ifelse(df_bes$trustMPs == "No trust", 1,
#                           ifelse(df_bes$trustMPs == "A great deal of trust", 7,
#                                  ifelse(df_bes$trustMPs == "Don't know", NA, as.numeric(df_bes$trustMPs))))
